<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>第一节课</title>
		<style type="text/css">
			/*去除原来样式*/
			
			* {
				padding: 0;
				margin: 0;
			}
			
			.container {
				width: 100vw;
				height: 100vh;
				display: flex;
				/*
				 * 将边框设置在中间
				 */
				align-items: center;
				justify-content: center;
			}
			
			canvas {
				width: 500px;
				height: 500px;
				border: 1px solid #333333;
			}
		</style>
	</head>

	<body>
		<div class="container">
			<canvas id="canvas" width="500" height="500"></canvas>
		</div>
	</body>

	<script>
		
		window.onload = function() {
			//let oCanvas = document.getElementById('canvas');
			let oCanvas = document.getElementById("canvas");
			let pen = oCanvas.getContext("2d");

			//createLinearGradient(x1,y1,x2,y2)
			//addColorStop(value1,color1);
			//addColorStop(value2,color2);
			
			//从左上角到右下角
			var gradual = pen.createLinearGradient(500,500,0,0);
			
			//从右上角到左下角
			//var gradual = pen.createLinearGradient(500,0,0,500);
			
			//从左到右
			//var gradual = pen.createLinearGradient(0,0,500,0);
			
			//从上到下
			//var gradual = pen.createLinearGradient(0,0,0,500);
			
			//填充
			gradual.addColorStop(0.5,"red");
			gradual.addColorStop(0.25,"blue");
			gradual.addColorStop(0.5,"green");
			gradual.addColorStop(0.75,"yellow");
			pen.fillStyle = gradual;
			
			//文字渐变
			pen.font = "100px bold";
			pen.fillText("Hello ",80,250);
			pen.fillText("World!",180,320);
			
			
			
			
			
			
			
			
		}
	</script>

</html>